﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core;
namespace WPFExcelReport
{
    class MVTVK02Report : BaseReport
    {
        #region ----------------PROPERTIES----------------------------------
        public OracleConnection OracleDB;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        public DataSet setUI = new DataSet();
        string ABPAUFFKRS;
        string ABPAUFFLFD;
        string ABPAUFFPOS;
        string DocType;
        string CellName = "";
        string CellValue = "";
        string strCompany;
        string strExcelFile;
        #endregion
        public MVTVK02Report()
            : base()
        {
        }
        public MVTVK02Report(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        {
            DocType = dicParamater["DocType"].ToString().Trim();
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            #region Excel  columns
            /*columns.Add("VAAART");
            columns.Add("DES");
            columns.Add("TOTWIDTH");
            columns.Add("VALWIDTH");
            columns.Add("WAFGRQM");
            columns.Add("WAFGRLFD");
            columns.Add("YARN");
            columns.Add("WABIND");
            columns.Add("WALOHNA");
            columns.Add("SUPP");
            columns.Add("COMP");
            columns.Add("WANEUD");
            columns.Add("REMARK");*/
            #endregion           						

        }
        #region------------------------------Function------------------------

         public void FillInExcelData(DataSet setSoruce, int xStart = 2, int yStart = 1)
        {
            try
            {
                int x = xStart, y = yStart;
                DataTable dtSoruce = setSoruce.Tables["WASTAMM"];                
                DataTable dtOutput = new DataTable();
                dtOutput.Columns.Add("PI", typeof(System.String));
                dtOutput.Columns.Add("CUSTOMER", typeof(System.String));
                dtOutput.Columns.Add("COUNTRY", typeof(System.String));
                dtOutput.Columns.Add("PROVINCE", typeof(System.String));
                dtOutput.Columns.Add("MERCHANDISER", typeof(System.String));
                dtOutput.Columns.Add("ENTRYDATE", typeof(System.String));
                dtOutput.Columns.Add("ENDCUSTOMER", typeof(System.String));
                dtOutput.Columns.Add("CURRENCY", typeof(System.String));
                dtOutput.Columns.Add("TYPE", typeof(System.String));
                dtOutput.Columns.Add("ARTICLE", typeof(System.String));
                dtOutput.Columns.Add("COLOR", typeof(System.String));
                dtOutput.Columns.Add("QTY", typeof(System.String));
                dtOutput.Columns.Add("QTYUNIT", typeof(System.String));
                dtOutput.Columns.Add("DELIVERYDATE", typeof(System.String));
                dtOutput.Columns.Add("PRICE", typeof(System.String));
                dtOutput.Columns.Add("PRICEUNIT", typeof(System.String));
                dtOutput.Columns.Add("TOTVALUES", typeof(System.String));
                dtOutput.Columns.Add("ARTCOL", typeof(System.String));
                dtOutput.Merge(dtSoruce, false, MissingSchemaAction.Ignore);

                exAgent.DataTableToExcel(dtOutput, 2, 1);

                int count = dtOutput.Rows.Count;

                exAgent.SetCellValue(1, 1, 1);
                exAgent.BatchConvert2Number(2, 12, count + 1, 12);
                exAgent.BatchConvert2Number(2, 15, count + 1, 15);
                exAgent.BatchConvert2Number(2, 17, count + 1, 17);
                exAgent.SetCellValue(1, 1, "PI");

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
         public override void WriteExcelReport(string fileType)
        {
            string filename = "";
            string sheetName = "";
            string Standard = "VK02";
            strExcelFile = @"MVT\MVTStandard.xls";
            string filePath = @"C:\intex.w\Report\" + strExcelFile;
            exAgent.Open(filePath);
            exAgent.Company = strCompany;
            exAgent.strExcelFile = strExcelFile;
            string filedate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            filename = @"订单统计" + filedate + ".xls";
            sheetName = DateTime.Now.ToShortTimeString().Replace(@":", "");
            exAgent.CreateNewSheet(filename, Standard, sheetName);
            FillInExcelData(dsSource, 2, 1);
            base.WriteExcelReport("OpenExcel");
        }
        #endregion
    }
}